import router from './router'
import { getToken } from '@/utils/auth'
// import {getMenu} from "@/api/user";

router.beforeEach((to, from, next) => {
  const hasToken = getToken()
  console.log("to",to)
  if (to.matched.some(route => route.meta.requiresAuth)) {
    if (hasToken) {
      // let path = to.fullPath
      // getMenu().then((res)=>{
      //   let allPath =  []
      //   res.data.forEach((item)=>{
      //     allPath.push(item.paths)
      //   })
      //   console.log("allPath",allPath)
      //
      //   if (!allPath.includes(path)){
      //     next("/")
      //   }
      // })

      next()
    } else {
      next(`/login?redirect=${to.path}`)
    }
  } else {
    next()
  }
})

